<?php
/**
 * Created by PhpStorm.
 * User: moquan
 * Date: 2018/5/26
 * Time: 17:16
 */

namespace app\admin\controller;
use app\admin\model\AdminModel;
use app\admin\model\AdminUser;
use app\admin\model\MenuModel;
use think\Controller;
use think\Log;
use think\Request;

class Base extends Controller{
    protected $adminID;

    protected $adminInfo = array();


    public function __construct(Request $request = null) {
//        Hook::add('index','app\\admin\\behavior\\Test');
        parent::__construct($request);

    }

    public function _initialize() {
        parent::_initialize();
//        $this->testMenu();

        if( AdminModel::isMustLogin() ) {
            $this->redirect('admin/admin/login');
        }else{
            $this->adminInfo = session('admin');
            $admin = AdminUser::getAdminUserById( $this->adminInfo['admin_id']);
            $roleMenuAuth = $admin['role']['menu_auth'] ? implode(',', $admin['role']['menu_auth']) : '';

            if ( $this->adminInfo['admin_id'] == 1) {
                $roleMenuAuth = 'all';
            }

            if ( $roleMenuAuth ) {
                $location = MenuModel::getLocation();
                //顶部菜单
                $this->assign('topMenu',MenuModel::getTopMenu( $roleMenuAuth ) );
//                $test = $location;
//                dump($test);
                //左侧菜单
                $this->assign('sideBarMenu',MenuModel::getSidebarMenu( '', $roleMenuAuth ) );
                //面包屑
                $this->assign('locationMenu',$location);
                //面包屑
                $this->assign('adminData', $this->adminInfo);
                // 操作权限
                $this->assign('operationAuth', MenuModel::getOperationAuth( $location[count($location) -1 ]['url_value'], $roleMenuAuth ) );

//                dump(MenuModel::getOperationAuth( $location[count($location) -1 ]['url_value'], $roleMenuAuth )->toArray());
//            Log::write(session('admin'),'print');
            }
            // 没有权限
        }
    }

    function testMenu(){
//        $top = MenuModel::getTopMenu();
//        $left = MenuModel::getSidebarMenu();
//        $location = MenuModel::getLocation();
//        dump(MenuModel::getLocation());
    }




}